<script type="text/javascript" charset="utf-8" src="/ueditor/ueditor.config.js"></script>
<script type="text/javascript" charset="utf-8" src="/ueditor/ueditor.all.min.js"> </script>
<script type="text/javascript" charset="utf-8" src="/ueditor/lang/zh-cn/zh-cn.js"></script>
<script type="text/javascript" charset="utf-8" src="/My97DatePicker/WdatePicker.js"></script>

<style>
    #login-button{
        background: #286090!important;
        color: white!important;
        border: 1px solid #286090!important;
        border-radius: 3px;
    }
    .form table td {
        /*width: 1%;*/

    }
    .freeLable{
        display: inline-block;
        width: 100px;
    }
    .integral{
        display: inline-block;
    }
    .up_file {  position:relative;  text-decoration:none; text-indent:0;margin-top: -10px}
    .up_file input { position:absolute; right:0; top:0; opacity:0; width: 100%;}
</style>
<div class="span10">
    <div style="margin-bottom: 20px;">
        <a href="/index/index">首页</a>
        <span >&gt;</span>
        <span>热门活动管理</span>
        <span >&gt;</span>
        <span>添加</span>
    </div>
    <form class="form" method="post" action="<?php echo baseUrl."/content/hot-active/add"?>" enctype="multipart/form-data">
        <table>
            <tr>
                <td style="width: 6%;">活动名称 *</td>
                <td ><input type="text" style="width: 600px;" name="title" placeholder="" value="<?php echo isset($data)? $data['title']:''?>"/></td>
            </tr>
            <?php if(isset($data)) {
                $str = '<tr>';
                $str .= '<td>原图片:</td>';
                $str .= '<td>';
                $pic = $data['pic'];
                $str .= "<input name='pic' type='text' value='" . $pic . "'></td></tr>";
                echo $str;
            } ?>

            <tr>
                <td>封面图 *:</td>
                <td>
                    <input id="file" type="file" name="pic" >
                </td>
            </tr>
            <tr>
                <td>活动时间 *</td>
                <td>
                    <input class="input-small Wdate" onclick="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss'})" type="text" style="width: 150px;" name="startTime" value="<?php echo isset($data['startTime']) ? $data['startTime'] : '' ?>" autocomplete="off"
/> - <input style="width: 150px;" class="input-small Wdate" onclick="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss'})" size="20" type="text" name="endTime" value="<?php echo isset($data) ? $data['endTime'] : '' ?>" autocomplete="off"
/>
                </td>

            </tr>

            <tr>
                <td>选择类别</td>
                <td>
                    <select name="cate" id="cate" onchange="changeCate()">
                        <option value="">请选择类别</option>
                        <option value="1" <?php echo isset($data) && $data['cate'] == "1" ? 'selected' : '' ?>>公开课</option>
                        <option value="2" <?php echo isset($data) && $data['cate'] == "2" ? 'selected' : '' ?>>训练营</option>
                        <option value="3" <?php echo isset($data) && $data['cate'] == "3" ? 'selected' : '' ?>>免费试听</option>
                        <option value="4" <?php echo isset($data) && $data['cate'] == "4" ? 'selected' : '' ?>>抽奖活动</option>

                    </select>
                </td>
            </tr>
            <tr class="videoClass">
                <td>回放sdk</td>
                <td><input type="text" style="width: 600px;" name="sdk" value="<?php echo isset($data) ? $data['sdk'] : '' ?>"/></td>
            </tr>
            <tr class="videoClass">
                <td>视频封面</td>
                <td>
                    <input type="text" style="width: 300px" value="<?php echo isset($data)? $data['image']:''?>" class="videoImage" name="image">
                    <a href="#" class="btn btn-info up_file">上传图片<input type="file" onchange="upImage(this)" accept="image/*"/></a>
                </td>
            </tr>
            <tr class="videoClass">
                <td>是否免费</td>
                <td>
                    <label class="freeLable">
                        <input type="radio"  name="free" value="0" <?php echo isset($data)&&$data['free']==0?'checked':''?>/>是
                    </label>
                    <label class="freeLable">
                        <input type="radio"  name="free" value="1" <?php echo isset($data)&&$data['free']==1?'checked':''?>/>否
                    </label>
                    <label class="integral">
                        消耗蜜糖：<input type="text" style="width: 100px;" name="integral" value="<?php echo isset($data) ? $data['integral'] : '' ?>"/></td>
                    </label>
            </tr>
            <?php if(isset($data)) {
                $str = '<tr class="videoClass">';
                $str .= '<td>原课程介绍图</td>';
                $str .= '<td>';
                $course_description = $data['course_description'];
                $str .= "<input name='course_description' type='text' value='" . $course_description . "'></td></tr>";
                echo $str;
            } ?>
            <tr class="videoClass">
                <td>课程介绍图</td>
                <td>
                    <input id="file" type="file" name="course_description" >
                </td>
            </tr>

            <tr>
                <td>活动详情 *：</td>
                <td>
                    <textarea type="text/plain" id="intro" name="content" placeholder="课程介绍" style="height:400px;width:70%"><?php echo isset($data) ? $data['content'] : '' ?></textarea>
                </td>
            </tr>

            <tr>
                <td>报名数 *</td>
                <td ><input type="text" style="width: 100px;" name="reservations" placeholder="" value="<?php echo isset($data)? $data['reservations']:''?>"/></td>
            </tr>
            <tr>
                <td>浏览量 *</td>
                <td ><input type="text" style="width: 100px;" name="viewCount" placeholder="" value="<?php echo isset($data)? $data['viewCount']:''?>"/></td>
            </tr>
            <tr>
                <td>是否置顶:</td>
                    <input type="hidden" name="isTop" class="isTop" value="<?php echo isset($data)? $data['isTop']:'0'?>">
                <td>
                    <?php if (isset($data)&& $data['isTop']==1) {?>
                        <a class="link-update" href="javascript:void(0)">取消置顶</a>
                    <?php }else{?>
                        <a class="link-update" href="javascript:void(0)">置顶</a>
                   <?php }?>
                </td>
            </tr>
            <tr>
                <td colspan="2" align="center"> <button type="submit" id="login-button"><?php echo isset($data)? '修改':'添加'?></button></td>
            </tr>
            <input type="hidden" name='id' value="<?php echo isset($data)? $data['id']:''?>"/>
            <input type="hidden" name="_csrf" value="<?=Yii::$app->request->getCsrfToken()?>" />
        </table>
    </form>
</div>
<script>
    //实例化编辑器
//    var ue = UE.getEditor('editor');
//    var plan = UE.getEditor('plan');
    var intro = UE.getEditor('intro');
</script>

<script type="text/javascript">
    $('.link-update').click(function(){
        var isTop = $(".isTop").val();
        if (isTop == "1") {
            $(".isTop").val("0");
            $(".link-update").text("置顶");
        } else {
            $(".isTop").val("1");
            $(".link-update").text("取消置顶");
        }
    })

    function upImage(obj) {
        var data = new FormData();
        var file = $(obj).get(0).files[0];
        if(!file){
            return false;
        }
        data.append('file', file);
        $.ajax({
            type: 'POST',
            url: "/content/api/up-image",
            dataType: "json",
            contentType:false,
            processData: false,
            data: data,
            success: function(res) {
                alert(res.message)
                if(res.code == 1){
                    $('.videoImage').val(res.path);
                }
            },
            error: function(e){
                alert('系统错误，请重试')
            },
        });
    }

    function changeCate() {
        var cate = $('#cate').val();
        if(cate==1){
            $('.videoClass').show();
        }else{
            $('.videoClass').hide();
        }
    }
    changeCate();
</script>